<?php

namespace Xlib\Form;

use Zend\Form\Form             as ZendForm;
use Zend\Form\View\Helper\Form as FormHelper;
use Xlib\Form\Element;

class Form extends ZendForm {

    public function __toString()
    {
        $formHelper = new FormHelper();
        $content = $formHelper->openTag($this);
        foreach ($this as $element) {
            if ($element instanceof ElementInterface) {
                $content .= (string) $element;
            } else {
                // throw
            }
        }
        $content .= $formHelper->closeTag();
        return $content;
    }

    protected function createTextElement ($name, array $options = null)
    {
        return new Element\Text($name, (array) $options);
    }

    protected function addTextElement ($name, array $options = null)
    {
        $this->add($this->createTextElement($name, $options));
    }

    protected function createPasswordElement ($name, array $options = null)
    {
        return new Element\Password($name, (array) $options);
    }

    protected function addPasswordElement ($name, array $options = null)
    {
        $this->add($this->createPasswordElement($name, $options));
    }

    protected function createCsrfElement ($name, array $options = null)
    {
        return new Element\Csrf($name, (array) $options);
    }

    protected function addCsrfElement ($name, array $options = null)
    {
        $this->add($this->createCsrfElement($name, $options));
    }

    protected function createSubmitElement ($name, array $options = null)
    {
        return new Element\Submit($name, (array) $options);
    }

    protected function addSubmitElement ($name, array $options = null)
    {
        $this->add($this->createSubmitElement($name, $options));
    }

}